package com.ming.easyDevelop.service.impl;

import com.ming.easyDevelop.mappers.CategoriesMapper;
import com.ming.easyDevelop.entity.po.Categories;
import com.ming.easyDevelop.entity.query.CategoriesQuery;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ming.easyDevelop.service.CategoriesService;
import com.ming.easyDevelop.entity.vo.PaginationResVo;
import com.ming.easyDevelop.entity.baseEnum.PageSize;
import com.ming.easyDevelop.entity.query.base.SimplePage;
@Service("categoriesService")
public class CategoriesServiceImpl implements CategoriesService {
	private final CategoriesMapper<Categories, CategoriesQuery> categoriesMapper;

	public CategoriesServiceImpl(CategoriesMapper categoriesMapper){
		this.categoriesMapper = categoriesMapper;
	}
	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Categories> findListByParam(CategoriesQuery query){
		return this.categoriesMapper.selectList(query);
	}

	/**
	 * 根据条件查询数量
	 */
	@Override
	public Long findCountByParam(CategoriesQuery query){
		return this.categoriesMapper.selectCount(query);
	}

	/**
	 * 根据条件分页查询列表
	 */
	@Override
	public PaginationResVo<Categories> findListByPage(CategoriesQuery query){
		Long count = this.findCountByParam(query);
		int pageSize = query.getPageSize() == null ? PageSize.SIZE20.getSize() : query.getPageSize();
		SimplePage simplePage = new SimplePage(query.getPageNo(), pageSize, Math.toIntExact(count));
		List<Categories> res = this.findListByParam(query);
		return new PaginationResVo<Categories>(query.getSimplePage().getPageNo(), query.getSimplePage().getPageSize(), query.getSimplePage().getCountTotal(), query.getSimplePage().getPageTotal(), res);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Long addBatch(List<Categories> list){
		return this.categoriesMapper.insertBatch(list);
	}

	/**
	 * 新增
	 */
	@Override
	public Long add(Categories bean){
		return this.categoriesMapper.insert(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdate(Categories bean){
		return this.categoriesMapper.insertOrUpdate(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdateBatch(List<Categories> list){
		return this.categoriesMapper.insertOrUpdateBatch(list);
	}

	/**
	 * 根据CategoryID查询
	 */
	@Override
	public Categories getByCategoryID(Integer categoryID){
		return this.categoriesMapper.selectByCategoryID(categoryID);
	}

	/**
	 * 根据CategoryID更新
	 */
	@Override
	public Long updateByCategoryID(Categories bean, Integer categoryID){
		return this.categoriesMapper.updateByCategoryID(bean,categoryID);
	}

	/**
	 * 根据CategoryID删除
	 */
	@Override
	public Long deleteByCategoryID(Integer categoryID){
		return this.categoriesMapper.deleteByCategoryID(categoryID);
	}

	/**
	 * 根据CategoryName查询
	 */
	@Override
	public Categories getByCategoryName(String categoryName){
		return this.categoriesMapper.selectByCategoryName(categoryName);
	}

	/**
	 * 根据CategoryName更新
	 */
	@Override
	public Long updateByCategoryName(Categories bean, String categoryName){
		return this.categoriesMapper.updateByCategoryName(bean,categoryName);
	}

	/**
	 * 根据CategoryName删除
	 */
	@Override
	public Long deleteByCategoryName(String categoryName){
		return this.categoriesMapper.deleteByCategoryName(categoryName);
	}

}
